package com.newly.common.core.utils;

import org.apache.commons.mail.HtmlEmail;

import java.util.UUID;

public class EmailUtils {
    private final static String sender = "newlyai@163.com";
    private final static String pwd = "LVQJBKFIICWWVDYO";
    //邮箱验证码
    public static boolean sendEmail(String emailAddress, String code) {
        try {
            HtmlEmail email = new HtmlEmail();//不用更改
            email.setHostName("smtp.163.com");//需要修改，126邮箱为smtp.126.com,163邮箱为163.smtp.com，QQ为smtp.qq.com
            email.setCharset("UTF-8");
            email.addTo(emailAddress);// 收件地址
            email.setFrom(sender, "北海市货运源头企业信息采集系统");//此处填邮箱地址和用户名,用户名可以任意填写
            email.setAuthentication(sender, pwd);
            email.setSubject("北海市货运源头企业信息采集系统验证码");//此处填写邮件名，邮件名可任意填写
            email.setMsg("尊敬的用户您好,您的验证码是:" + code);//此处填写邮件内容
            email.send();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 生产随机验证码
     * @return
     */
    public static String getVerificationCode() {
        UUID uuid = UUID.randomUUID();
        return uuid.toString().substring(0,6);
    }

}
